<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>upload</title>
</head>
<body>
这是文件上传页面
<!--<form action="/upload" method="post" enctype="multipart/form-data">-->
<!--    <input type="file" name="file">-->
<!--    <br>-->
<!--    <button type="submit">提交</button>-->
<!--</form>-->
<form>
    <input type="file" name="file" id="upload_file">
    <br>
    <button type="button" id="sub_btn">提交</button>
</form>
<script src="/static/js/jquery-3.4.1.js"></script>
<script>
    var sub_btn = document.getElementById("sub_btn")
    sub_btn.onclick = function () {
        var file = document.getElementById("upload_file").files
        console.log(file)
        var formData = new FormData()
        formData.append('file', file[0])
        console.log(formData)
        $.ajax({
            url: "/upload_ajax",
            method: "POST",
            data: formData,
            processData: false,
            contentType: false,
            success: function (data) {
                alert(data)
            },
            fail: function (err) {
                console.log(err)
            }
        })
    }
</script>
</body>
</html>